import threading
from PyQt5.QtWidgets import *

from py_base.window.window_base import WinBase, WidgetParam, DTYPE_FLOAT
from src import enum, logic

set_times = 0


class Gui(WinBase):
    def __init__(self):
        WinBase.__init__(self)

        self.setWindowTitle('vr2战警自动化')

        self.addLabRow("x偏移量", QLineEdit(), 'x_offset', dataType=DTYPE_FLOAT)
        self.addLabRow("y偏移量", QLineEdit(), 'y_offset')
        self.addLabRow("窗口名称,$开头表示精确匹配", QLineEdit(), 'win_title')

        self.addLabRow("目标hsv", QLineEdit(), 'target_hsv')
        self.addLabRow("准星hsv", QLineEdit(), 'shot_hsv')

        driver = QComboBox(self)
        driver.addItem("ghub_device")
        driver.addItem("MouseControl")
        self.addLabRow("鼠标驱动", driver, 'driver')

        self.addLabRows([WidgetParam("自动射击", QCheckBox(), 'auto_shot'), WidgetParam("自动装弹", QCheckBox(), 'auto_reload')])
        self.addLabRow("预览缩放", QLineEdit(), 'resize', dataType=DTYPE_FLOAT)

        self.info = self.addRow(QLabel(""))

        self.begin_btn = self.addBtn("开始", self.beginPredict)
        self.initSetting()
        self.setLayout(self.vbox)

    def setPredict(self, open):
        if open:
            enum.predicting = True
            self.begin_btn.setText("停止")
            threading.Thread(target=logic.begin).start()

        else:
            enum.predicting = False
            self.begin_btn.setText("开始")

    def beginPredict(self):
        self.setPredict(not enum.predicting)
